package photorganizer.common.bean;

import java.util.Properties;

public class MappingLocator extends LocatorAbstract {

	public static final String IMPLEMENTATION_SUFFIX = "Impl";

	public MappingLocator(Locator delegate, Properties properties) {
		super(delegate, properties);
	}

	@Override
	public <T> T get(Class<T> beanClass) {
		String beanClassName = beanClass.getName();

		String mappedClassName = getProperty(beanClassName);
		if (mappedClassName != null) {
			return get(beanClass, mappedClassName);
		}

		if (beanClass.isInterface()) {
			return get(beanClass, beanClassName + IMPLEMENTATION_SUFFIX);
		}

		return super.get(beanClass);
	}

}